/*******************************************************************************
 * This code is totally free to edit and be distributed
 * Author: José Manuel Portero García (jmporterog@gmail.com)
 ******************************************************************************/
/**
 * 
 */
package gazpachito.examples.dozer.mapper;

import java.util.HashSet;
import java.util.Set;

import etm.core.configuration.EtmManager;
import etm.core.monitor.EtmMonitor;
import etm.core.monitor.EtmPoint;
import gazpachito.examples.dozer.facade.ChildBO;
import gazpachito.examples.dozer.facade.ParentBO;
import gazpachito.examples.dozer.persistence.ChildVO;
import gazpachito.examples.dozer.persistence.ParentVO;

/**
 * @author jmporterog
 *
 */
public class ManualParentMapper implements ParentMapper {
	
	private static final EtmMonitor ETM_MONITOR = EtmManager.getEtmMonitor();
	
	/*
	 * (non-Javadoc)
	 * @see gazpachito.examples.dozer.mapper.ParentMapper#map(gazpachito.examples.dozer.persistence.ParentVO)
	 */
	public ParentBO map(ParentVO parentVO) {
		EtmPoint point = ETM_MONITOR.createPoint("ManualParentMapper:map");
		
		ParentBO parentBO = null;
		if (parentVO != null) {
			parentBO = new ParentBO();
			parentBO.setBusinessId(parentVO.getPersistenceId());
			parentBO.setName(parentVO.getName());
			if (parentVO.getChildVOs() != null) {
				Set<ChildBO> childBOs = new HashSet<ChildBO>();
				for (ChildVO childVO : parentVO.getChildVOs()) {
					ChildBO childBO = map(childVO);
					childBO.setParentBO(parentBO);
					childBOs.add(childBO);
				}
				parentBO.setChildBOs(childBOs);
			}
		}
		
		point.collect();
		
		return parentBO;
	}

	/*
	 * (non-Javadoc)
	 * @see gazpachito.examples.dozer.mapper.ParentMapper#map(gazpachito.examples.dozer.persistence.ChildVO)
	 */
	public ChildBO map(ChildVO childVO) {
		ChildBO childBO = new ChildBO();
		childBO.setBusinessId(childVO.getPersistenceId());
		childBO.setPrice(childVO.getPrice());
		return childBO;
	}
}
